package com.service.impl;

import com.mapper.DeptMapper;
import com.pojo.Dept;
import com.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service // 表示当前类被Spring管理
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public Dept findDeptById(Integer id) {
        return deptMapper.findDeptById(id);
    }

    @Override
    public int getCount() {
        return deptMapper.getCount();
    }

    @Override
    @Transactional
    public int insertDeptBatch() {
        int count = 0;
        for (int i = 8; i < 13; i++) {
            Dept dept = new Dept();
            dept.setDeptno(i);
            dept.setDname("dept" + i);
            dept.setLoc("loc" + i);
            count += deptMapper.insertDept(dept);
        }
        return count;
    }
}
